﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rhomble.Data.Projects
{
	public class ProjectRepository : UserOnlyRepository, IRepository<Project>
	{
		public ProjectRepository(string userName) : base(userName) { }

		public IQueryable<Project> GetQuery()
		{
			return Context.Projects;
		}

		public void AddNew(Project entity)
		{
			var user = GetCurrentUser();

			entity.ProjectPK = Guid.NewGuid();
			entity.CreatedDate = DateTime.Now;
			entity.CreatedBy = user.UserId;

			Context.Projects.AddObject(entity);
			SaveChanges();
		}

		public void Update(Guid id, Project project)
		{
			var entity = GetQuery()
							.WithID(id)
							.Single();

			entity.Name = project.Name;
			SaveChanges();
		}
	}
}
